/*
 * @Author: Eureka 
 * @Date: 2020-09-14 10:16:16 
 * @Last Modified by: Eureka
 * @Last Modified time: 2021-11-10 17:43:09
 */
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:senkoo_platform/Utils/is_empty.dart';
import 'package:senkoo_platform/base_image/image_utils.dart';

/// 图片加载（支持本地与网络图片）
class LoadImage extends StatelessWidget {
  const LoadImage(this.image,
      {Key? key,
      this.width,
      this.height,
      this.fit = BoxFit.contain,
      this.format = "png",
      this.holderImg = ""})
      : super(key: key);

  final String image;
  final double? width;
  final double? height;
  final BoxFit fit;
  final String format;
  final String holderImg;

  @override
  Widget build(BuildContext context) {
    if (EmptyUtil.isEmpty(image) || image == "null") {
      return LoadAssetImage(holderImg,
          height: height, width: width, fit: fit, format: format);
    } else {
      if (image.startsWith("http")) {
        return ExtendedImage.network(
          image,
          fit: BoxFit.contain,
          mode: ExtendedImageMode.gesture,
          initGestureConfigHandler: (state) {
            return GestureConfig(
              minScale: 0.9,
              animationMinScale: 0.7,
              maxScale: 3.0,
              animationMaxScale: 3.5,
              speed: 1.0,
              inertialSpeed: 100.0,
              initialScale: 1.0,
              inPageView: false,
              initialAlignment: InitialAlignment.center,
            );
          },
        );
      } else {
        return LoadAssetImage(image,
            height: height, width: width, fit: fit, format: format);
      }
    }
  }
}

/// 加载本地资源图片
class LoadAssetImage extends StatelessWidget {
  const LoadAssetImage(this.image,
      {Key? key,
      this.width,
      this.height,
      this.fit,
      this.format = 'png',
      this.color})
      : super(key: key);

  final String? image;
  final double? width;
  final double? height;
  final BoxFit? fit;
  final String format;
  final Color? color;

  @override
  Widget build(BuildContext context) {
    return Image.asset(
      ImageUtils.getImgPath(image, format: format),
      height: height,
      width: width,
      fit: fit,
      // color: isDark ? HexColor('#ffffff') : color,
      color: color,
    );
  }
}
